package taskmanager;

import taskinstance.TaskFactory;
import taskinstance.TaskType;

public class Main {
  public static void main(String[] args) throws InterruptedException {

    String[] allIps = {"A", "B", "C", "D", "E"};

    TaskManager tm = new TaskManager(allIps);
    // add a instant task, the source side is G, the target side is B, the file to be transmit is
    // file1.
    // for now, the source side is useless.
    tm.addTask(TaskFactory.createTask(TaskType.INSTANT_TASK, "G", "B", "file1.txt", false, false));

    // add a timing task, the task will start at the time according to the 4th parameter.
    // if the time is before the current time, this task will start immediately as the instant task.
    tm.addTask(TaskFactory.createTask(TaskType.TIMING_TASK, "G", "E", "test9",
        "2015/10/23 18:23:10", false, false));

    // add a period task, the task will run period at a frequency of 40 seconds according to the 4th
    // parameter.
    tm.addTask(TaskFactory.createTask(TaskType.PERIOD_TASK, "G", "B", "fileP", "40", false, false));



    TaskManager tmCenter = new TaskManagerCenter(allIps);
    tmCenter.addTask(TaskFactory.createTask(TaskType.INTERMEDIATE_TASK, "A", "B", "test.txt",
        false, false));
    tmCenter.addTask(TaskFactory.createTask(TaskType.INTERMEDIATE_TASK, "B", "C", "testzzz.txt",
        false, false));

    // other task for testing...
    // tm.addTask(TaskFactory.createTask("G", "B", "test2.txt", "", 0));
    // tm.addTask(TaskFactory.createTask("G", "B", "test3.txt", "", 0));
    // tm.addTask(TaskFactory.createTask("G", "B", "test4.txt", "", 0));
    // tm.addTask(TaskFactory.createTask("G", "B", "test5.txt", "", 0));
    // tm.addTask(TaskFactory.createTask("G", "C", "test6.txt", "", 0));
    // tm.addTask(TaskFactory.createTask("G", "D", "test7", "", 0));
    // tm.addTask(TaskFactory.createTask("G", "D", "test8", "", 0));
    // tm.addTask(TaskFactory.createTask("G", "E", "test11.txt", "", 0));
    //
    // tm.addTask(TaskFactory.createTask("G", "E", "test9", "2015/10/23 18:23:10", 1));
    // tm.addTask(TaskFactory.createTask("G", "A", "test10", "2015/10/22 17:23:20", 1));

    while (true) {
      Thread.sleep(5000); // query task progress every 5 seconds.
      tm.queryTaskState();
    }

  }
}
